package com.hudie;

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.StringReader;
import java.io.UnsupportedEncodingException;
import java.net.URL;


import com.google.gson.stream.JsonReader;


//import com.google.appengine.repackaged.org.json;

public class ParseWeatherJsonData {
	//private String weatherinfo = null;
	//public String getWeatherInfo(){
	//	return weatherinfo;
	//}
	public static String getCityWeather() throws UnsupportedEncodingException, IOException{
		URL url = new URL("http://m.weather.com.cn/data/101030100.html");

		// 读取源码
		BufferedReader reader = new BufferedReader( new InputStreamReader(url.openStream(),"UTF-8"));
		String weather = "";
		String line = "";
		while ((line = reader.readLine()) != null)
			weather += line;
		return parseWeather(weather);
	}
	public static String parseWeather(String weather) throws IOException{
		String tagname = null;
		JsonReader reader = new JsonReader(new StringReader(weather));
		reader.beginArray();
		while(reader.hasNext()){
			reader.beginObject();
			while(reader.hasNext()){
				tagname = reader.nextName()+reader.nextString();
			}
			reader.endObject();
		}
		reader.endArray();
		
		return tagname;
	}
		
//		String weather = gson.
//		String city = jsonob.getString("city");
//		System.out.println(city);
//		
//		String date_y = jsonob.getString("date_y");
//		System.out.println(date_y);
//		
//		String weather1 = jsonob.getString("weather1");
//		System.out.println(weather1);
//		
//		String temp1 = jsonob.getString("temp1");
//		System.out.println(temp1);
//		
//		String index_d = jsonob.getString("index_d");
//		System.out.println(index_d);
//		
//		 return  city+date_y+weather1+temp1+index_d;
}